/**************************提示：只允许修改开发区域，其他区域会被覆盖！********************************/
mod.definePage("extend/cp/bc/js/TravelAccountBill_Edit_Open001_copy",function(waf){
    //@beginUseModule
    var bizCollBillBase = mod.useSync("cp/bc/js/bizCollBillBase");
    var bizCollBillEdit = mod.useSync("cp/bc/js/bizCollBillEdit");
    var promptExpenseType = mod.useSync("cp/bc/js/promptExpenseType");
    var TravelAccountBill_Edit_Open = mod.useSync("cp/bc/js/TravelAccountBill_Edit_Open");
    //@endUseModule
    var _public = {},_private = {},me=_self;
    //@beginPublic
    waf.extend(_public,{
        //控件事件描述:
        inlandForeignChange:function(event,ui){
             return _private.inlandForeignChange(event,ui);
        }
	    ,
        //控件事件描述:
        subsidyDayChange:function(event,value){
             return _private.subsidyDayChange(event,value);
        }
	    ,
        //控件事件描述:
        trafficCurrencyChange:function(event,value){
             return _private.trafficCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        meetingCurrencyChange:function(event,value){
             return _private.meetingCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        otherCurrencyChange:function(event,value){
             return _private.otherCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        hotelCurrencyChange:function(event,value){
             return _private.hotelCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        fsCurrencyChange:function(event,value){
             return _private.fsCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        tsCurrencyChange:function(event,value){
             return _private.tsCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        pfCurrencyChange:function(event,value){
             return _private.pfCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        lifeSubsidyCurrencyChange:function(event,value){
             return _private.lifeSubsidyCurrencyChange(event,value);
        }
	    ,
        //控件事件描述:
        startDateChange:function(changeValue,inst){
             return _private.startDateChange(changeValue,inst);
        }
	    ,
        //控件事件描述:
        dutyOnClick:function(){
             return _private.dutyOnClick();
        }
	    ,
        //控件事件描述:
        dutyOnChange:function(event,ui){
             return _private.dutyOnChange(event,ui);
        }
	    ,
        //控件事件描述:
        destinationCityChange:function(event,value){
             return _private.destinationCityChange(event,value);
        }
	    ,
        //控件事件描述:
        putUpDayChange:function(event,value){
             return _private.putUpDayChange(event,value);
        }
	    ,
        //控件事件描述:
        trafficRateChange:function(event,value){
             return _private.trafficRateChange(event,value);
        }
	    ,
        //控件事件描述:
        mettingRateChange:function(event,value){
             return _private.mettingRateChange(event,value);
        }
	    ,
        //控件事件描述:
        otherRateChange:function(event,value){
             return _private.otherRateChange(event,value);
        }
	    ,
        //控件事件描述:
        hotelRateChange:function(event,value){
             return _private.hotelRateChange(event,value);
        }
	    ,
        //控件事件描述:
        fsRetaChange:function(event,value){
             return _private.fsRetaChange(event,value);
        }
	    ,
        //控件事件描述:
        tsRetaChange:function(event,value){
             return _private.tsRetaChange(event,value);
        }
	    ,
        //控件事件描述:
        pfRetaChange:function(event,value){
             return _private.pfRetaChange(event,value);
        }
	    ,
        //控件事件描述:
        lifeSubsidyRetaChange:function(event,value){
             return _private.lifeSubsidyRetaChange(event,value);
        }
	    ,
        //控件事件描述:
        costCenterChange:function(event,value){
             return _private.costCenterChange(event,value);
        }
	    ,
        //控件事件描述:
        endDateChange:function(changeValue,inst){
             return _private.endDateChange(changeValue,inst);
        }
	    ,
        //控件事件描述:
        jobNameOnChange:function(event,ui){
             return _private.jobNameOnChange(event,ui);
        }
	    ,
        //控件事件描述:
        bussesExpenseChange:function(event,value){
             return _private.bussesExpenseChange(event,value);
        }
	    ,
        //控件事件描述:
        meetingChange:function(event,value){
             return _private.meetingChange(event,value);
        }
	    ,
        //控件事件描述:
        otherExpenseChange:function(event,value){
             return _private.otherExpenseChange(event,value);
        }
	    ,
        //控件事件描述:
        hotelExpenseChange:function(event,value){
             return _private.hotelExpenseChange(event,value);
        }
	    ,
        //控件事件描述:
        foodSubsidyChange:function(event,value){
             return _private.foodSubsidyChange(event,value);
        }
	    ,
        //控件事件描述:
        trafficSubsidyChange:function(event,value){
             return _private.trafficSubsidyChange(event,value);
        }
	    ,
        //控件事件描述:
        publicFeesChange:function(event,value){
             return _private.publicFeesChange(event,value);
        }
	    ,
        //控件事件描述:
        lifeSubsidyChange:function(event,value){
             return _private.lifeSubsidyChange(event,value);
        }
	    ,
        //页面事件描述:
        initEntryGrid:function(e){
             return _private.initEntryGrid(e);
        }
	    ,
        //页面事件描述:
        verifyData:function(e){
             return _private.verifyData(e);
        }
	    ,
        //页面事件描述:
        moreVerifyData:function(e){
             return _private.moreVerifyData(e);
        }
	    ,
        //页面函数描述:分录金额合计
        entryMoenyChange:function(event,value){
             return _private.entryMoenyChange(event,value);
        }
	    ,
        //页面函数描述:分录-根据币种带出汇率
        entryReta:function(event,value,retaName){
             return _private.entryReta(event,value,retaName);
        }
	    ,
        //页面函数描述:分录控制隐藏/显示
        entryControlChange:function(){
             return _private.entryControlChange();
        }
	    ,
        //页面函数描述:目的城市过滤
        entryDestinationCityFiltration:function(){
             return _private.entryDestinationCityFiltration();
        }
	    ,
        //页面函数描述:天数差
        calcSubDays:function(startDate, endDate){
             return _private.calcSubDays(startDate, endDate);
        }
	    ,
        //页面函数描述:判断分录是否跨季节
        entryIsCrossSeason:function(){
             return _private.entryIsCrossSeason();
        }
    });
    _self.subscribeEvent("fieldOnLoadEvent",_public.initEntryGrid,"after");
    _self.subscribeEvent("preSaveRowActionEvent",_public.verifyData,"before");
    _self.subscribeEvent("addMoreRowActionEvent",_public.moreVerifyData,"before");
    //@endPublic
    //@beginTemplateFunctions

    //@endTemplateFunctions

    /**************************开发区域开始**********************************************/
    //@beginPrivate
    waf.extend(_private,{
      // 分录求合计金额时,需要计算的相关属性
        entrySumProps: [ "bussesExpense","hotelExpense", "meeting", "otherExpense", "foodSubsidy", 
		           "trafficSubsidy","publicFees","lifeSubsidy"],
       entrySumReta: [ "trafficRate","hotelRate", "mettingRate", "otherRate", "fsReta", 
		           "tsReta","pfReta","lifeSubsidyReta"],
    	verifyData:function(event,value){
           var entryInfoBlock = waf("#entries");
    	  var rowid = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
          var startDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "startDate");
    	  var endDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "endDate");
          var checkInDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "checkInDate");
    	  var checkOutDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "checkOutDate");
          var putUpDay = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "putUpDay");
          
          var checkInDateID=entryInfoBlock.wafInfoBlock("getControlId", rowid, "checkInDate");
           var state=waf("#" + checkInDateID).wafDatePicker("option","disabled");
          
          var day=_private.calcSubDays(startDate,endDate);
              if(day<putUpDay){
                waf.msgBox.showWarning("住宿天数不能超过（到达日期-出发日期）的天数");
               throw SyntaxError();
              }
          if(!state){
              if(null==checkInDate){
                   waf.msgBox.showWarning("入住日期不能为空");
                  throw SyntaxError();
              }
            
             if(null==checkOutDate){
                   waf.msgBox.showWarning("退房日期不能为空");
                   throw SyntaxError();
              }
              day=_private.calcSubDays(checkInDate,checkOutDate);
              if(day!=putUpDay){
                waf.msgBox.showWarning("住宿天数必须等于（退房日期-入住日期）的天数");
               throw SyntaxError();
              }
            
          }
            var result=true; 
      	    var entry = waf("#entries");
            var entryData=entry.wafInfoBlock("getData")[0];
            var applierCompanyId=waf("#applierCompany").wafPromptBox('getValue').id; 
            var option=_self.getOptionFromArguments(arguments);
            option.action="TravelVerifyAction";
            option.data={"data":JSON.stringify(entryData),"applierCompanyId":applierCompanyId};
            option.async=false;
            option.success=function(data){
            	if(data.result==false){
                  result=false;
                 waf.msgBox.showWarning(data.msg);
               }
            }
          waf.doPost(option);
          
          if(!result){
             //return;
             throw SyntaxError();
          }
       }
    	,
		hotelExpenseChange:function(event,value){
            _private.entryMoenyChange(event,value);
        }
	    ,
        meetingChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        otherExpenseChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        foodSubsidyChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        bussesExpenseChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        trafficSubsidyChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        taxiExpenseChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        publicFeesChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
    	,
        entryMoenyChange:function(event,value){
          if(value.current!=null){
             var entryInfoBlock = waf("#entries");
    		 var curRowId = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
             var rowObj = entryInfoBlock.wafInfoBlock("getRowData", curRowId);
    		 var sumProps = _private.entrySumProps;
             var sumReta = _private.entrySumReta;
    		 var amountOri = 0;
    		for (var i = 0, il = sumProps.length; i < il; i++) {
    			amountOri += (rowObj[sumProps[i]] || 0)*(rowObj[sumReta[i]] || 0);
    		}
          entryInfoBlock.wafInfoBlock("setFieldValue", curRowId, "amountOri", String(amountOri));
            entryInfoBlock.wafInfoBlock("setFieldValue", curRowId, "amountOriWithoutTax", String(amountOri));
          }
        }
    	,
		entryTaxiExpenseChange:function(event,value){
          _private.entryMoenyChange(event,value);
        }
    	,
		trafficCurrencyChange:function(event,value){
			_private.entryReta(event,value,"trafficRate");
        }
	    ,
        trafficRateChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        fsCurrencyChange:function(event,value){
          _private.entryReta(event,value,"fsReta");
        }
	    ,
        tsCurrencyChange:function(event,value){
           _private.entryReta(event,value,"tsReta");
        }
	    ,
        pfCurrencyChange:function(event,value){
           _private.entryReta(event,value,"pfReta");
        }
	    ,
        hotelRateChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        mettingRateChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        otherRateChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        hotelCurrencyChange:function(event,value){
          _private.entryReta(event,value,"hotelRate");
        }
	    ,
        meetingCurrencyChange:function(event,value){
          _private.entryReta(event,value,"mettingRate");
        }
	    ,
        otherCurrencyChange:function(event,value){
          _private.entryReta(event,value,"otherRate");
        }
	    ,
        fsRetaChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        tsRetaChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        pfRetaChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
    	,
		entryReta:function(event,value,retaName){
          var exchangeRate = 1.00;
          if(value.current!=null){
				// 查询汇率
				waf.doPost({
					action: "onchange",
					data: {source:"currencyType", currencyType: value.current.id},
					showBlock: false,
					async: false,
					success: function(result) {
						if (result && result.precision) {
							exchangeRate = result.convertRate || 1.00;	// 汇率
						}
					}
				});
          }
			  // 分录-汇率赋值
          var entryInfoBlock = waf("#entries");
           var curRowId = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
           entryInfoBlock.wafInfoBlock("setFieldValue", curRowId, retaName, String(exchangeRate));
           _private.entryMoenyChange(event,value);
        }
    	,
		lifeSubsidyCurrencyChange:function(event,value){
           _private.entryReta(event,value,"lifeSubsidyReta");
        }
	    ,
        lifeSubsidyChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        lifeSubsidyRetaChange:function(event,value){
          _private.entryMoenyChange(event,value);
        }
    	,
		inlandForeignChange:function(event,ui){
             _private.entryControlChange();
           _private.entryDestinationCityFiltration();
        }
	    ,
        subsidyDayChange:function(event,value){
           //_private.entryControlChange();
          // _private.entryDestinationCityFiltration();
          
             var entryInfoBlock = waf("#entries");
             var curRowId = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
             var  destinationCity = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "destinationCity");
             var city=waf("#" +  destinationCity).wafPromptStandard("getValue");
            if(city!=null){
                   var option=_self.getOptionFromArguments(arguments);
                   option.action="EvectionSubsiAction";
                   option.data={"id":city.id};
                   option.async=false;
                   option.success=function(data){
                      //补贴天数
                     var day=value.current||0;
                     //伙食补贴
                     var foodSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "foodSubsidy");
                     waf("#" + foodSubsidy).wafNumberField("setValue",(data.mealsSubsidy||0)*day);
                     //交通补贴
                     var trafficSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficSubsidy");
                     waf("#" + trafficSubsidy).wafNumberField("setValue",(data.trafficSubsidy||0)*day);
                     //公杂费补贴
                     var publicFees = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "publicFees");
                     waf("#" + publicFees).wafNumberField("setValue",(data.affairSubsidy||0)*day);
                     // 生活补贴
                     var lifeSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidy");
                     waf("#" + lifeSubsidy).wafNumberField("setValue",((data.subsidy||0)/30).toFixed(2)*day);
                   }
                   waf.doPost(option);
            }
        }
    	,
		putUpDayChange:function(event,value){
         _private.entryIsCrossSeason();
        }
	    ,
        departurecityChange:function(event,value){
           var city=value.current.city;
            var entryInfoBlock = waf("#entries");
           var curRowId = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
           entryInfoBlock.wafInfoBlock("setFieldValue", curRowId, "from", city);
        }
	    ,
        destinationCityChange:function(event,value){
           if(value.current!=null){
              var city=value.current.city;
              var entryInfoBlock = waf("#entries");
              var curRowId = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
              entryInfoBlock.wafInfoBlock("setFieldValue", curRowId, "to", city);
             
             var option=_self.getOptionFromArguments(arguments);
             option.action="EvectionSubsiAction";
             option.data={"id":value.current.id};
             option.async=false;
             option.success=function(data){
                //补贴天数
               var subsidyDay = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "subsidyDay");
               var day=waf("#" + subsidyDay).wafNumberField("getValue")||0;
               //伙食补贴
               var foodSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "foodSubsidy");
               waf("#" + foodSubsidy).wafNumberField("setValue",(data.mealsSubsidy||0)*day);
               //交通补贴
               var trafficSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficSubsidy");
               waf("#" + trafficSubsidy).wafNumberField("setValue",(data.trafficSubsidy||0)*day);
               //公杂费补贴
               var publicFees = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "publicFees");
               waf("#" + publicFees).wafNumberField("setValue",(data.affairSubsidy||0)*day);
               // 生活补贴
               var lifeSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidy");
               waf("#" + lifeSubsidy).wafNumberField("setValue",((data.subsidy||0)/30).toFixed(2)*day);
             }
             waf.doPost(option);
           }
          
            if(value.current!=null&&value.current!=""){
                if(value.current.city==null||value.current.city==""){
                      var entryInfoBlock = waf("#entries");
                      var option=_self.getOptionFromArguments(arguments);
                      option.action="EvectionSubsiAction";
                      option.data={"id":value.current.id};
                      option.async=false;
                      option.success=function(data){
                          var curRowId = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
                          var destinationCity = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "destinationCity");
                          waf("#" + destinationCity).wafPromptBox("setValue",null);
                           waf("#" + destinationCity).wafPromptBox("setValue",data);
                       }
          			  waf.doPost(option);
               }
            }
        }
    	,
		entryControlChange:function(){
              var entryInfoBlock = waf("#entries");
               var curRowId = entryInfoBlock.wafInfoBlock("getCurrentRowId");
            //国内/国外
                var inlandForeign = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "inlandForeign");
                var inlandForeignValue=waf("#" + inlandForeign).wafSelect("getValue") || 0;
           if(inlandForeignValue==2){    //国外
                 var currencyType;
                 var option=_self.getOptionFromArguments(arguments);
                      option.action="CurrencyTypeAction";
                      option.data={"name":"美元"};
                      option.async=false;
                      option.success=function(data){
                          currencyType=data;
                       }
          			  waf.doPost(option);
             
               //职务等级
                var duty = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "duty");
                waf("#" + duty).wafSelect("option","disabled",true);
                waf("#" + duty).wafSelect("setValue",-1);
               //季节
                var season = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "season");
                waf("#" + season).wafSelect("option","disabled",true);
                waf("#" + season).wafSelect("setValue",-1);
               //补贴天数
               // var subsidyDay = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "subsidyDay");
               // var subsidyDayValue=waf("#" + subsidyDay).wafNumberField("getValue") || 0;
              var startDate = entryInfoBlock.wafInfoBlock("getFieldValue", curRowId, "startDate");
    		var endDate = entryInfoBlock.wafInfoBlock("getFieldValue", curRowId, "endDate");
             if(null==startDate||null==endDate){
             	 	return;
             }
             var day=_private.calcSubDays(startDate,endDate);
               if(day>30){
                  //职称
                  var jobName = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "jobName");
                  waf("#" + jobName).wafSelect("option","disabled",false);
               //伙食补贴
                var fsCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "fsCurrency");
                waf("#" + fsCurrency).wafPromptBox("option","disabled",true);
                 waf("#" + fsCurrency).wafPromptBox("setValue",null);
                var foodSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "foodSubsidy");
                waf("#" + foodSubsidy).wafNumberField("option","disabled",true);
                waf("#" + foodSubsidy).wafNumberField("setValue",0);
                var fsReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "fsReta");
                waf("#" + fsReta).wafNumberField("option","disabled",true);
               //交通补贴
               var tsCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "tsCurrency");
                waf("#" + tsCurrency).wafPromptBox("option","disabled",true);
                 waf("#" + tsCurrency).wafPromptBox("setValue",null);
                var trafficSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficSubsidy");
                waf("#" + trafficSubsidy).wafNumberField("option","disabled",true);
                waf("#" + trafficSubsidy).wafNumberField("setValue",0);
                var tsReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "tsReta");
                waf("#" + tsReta).wafNumberField("option","disabled",true);
               //公杂费补贴
               var pfCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "pfCurrency");
                waf("#" + pfCurrency).wafPromptBox("option","disabled",true);
                waf("#" + pfCurrency).wafPromptBox("setValue",null);
                var publicFees = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "publicFees");
                waf("#" + publicFees).wafNumberField("option","disabled",true);
                waf("#" + publicFees).wafNumberField("setValue",0);
                var pfReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "pfReta");
                waf("#" + pfReta).wafNumberField("option","disabled",true);
               //住宿费
               var hotelCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelCurrency");
                waf("#" + hotelCurrency).wafPromptBox("option","disabled",true);
                waf("#" + hotelCurrency).wafPromptBox("setValue",null);
                var hotelExpense = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelExpense");
                waf("#" + hotelExpense).wafNumberField("option","disabled",true);
                waf("#" + hotelExpense).wafNumberField("setValue",0);
                var putUpDay = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "putUpDay");
                waf("#" + putUpDay).wafNumberField("option","disabled",true);
                waf("#" + putUpDay).wafNumberField("setValue",0);              
                var hotelRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelRate");
                waf("#" + hotelRate).wafNumberField("option","disabled",true);
               // 生活补贴
                var lifeSubsidyCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidyCurrency");
                waf("#" + lifeSubsidyCurrency).wafPromptBox("option","disabled",false);
                waf("#" + lifeSubsidyCurrency).wafPromptBox("setValue",currencyType);
                var lifeSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidy");
                waf("#" + lifeSubsidy).wafNumberField("option","disabled",true);
                var lifeSubsidyReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidyReta");
                waf("#" + lifeSubsidyReta).wafNumberField("option","disabled",true);
                 
               }else{
                 
                   //职称
                  var jobName = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "jobName");
                  waf("#" + jobName).wafSelect("option","disabled",true);
                  waf("#" + jobName).wafSelect("setValue",-1);
                  //住宿费
               var hotelCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelCurrency");
                waf("#" + hotelCurrency).wafPromptBox("option","disabled",false);
                 waf("#" + hotelCurrency).wafPromptBox("setValue",currencyType);
                var hotelExpense = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelExpense");
                waf("#" + hotelExpense).wafNumberField("option","disabled",false);
                var putUpDay = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "putUpDay");
                waf("#" + putUpDay).wafNumberField("option","disabled",false);
                var hotelRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelRate");
                waf("#" + hotelRate).wafNumberField("option","disabled",true);
                   //伙食补贴
                var fsCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "fsCurrency");
                waf("#" + fsCurrency).wafPromptBox("option","disabled",false);
                 waf("#" + fsCurrency).wafPromptBox("setValue",currencyType);
                var foodSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "foodSubsidy");
                waf("#" + foodSubsidy).wafNumberField("option","disabled",true);
                var fsReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "fsReta");
                waf("#" + fsReta).wafNumberField("option","disabled",true);
               //交通补贴
               var tsCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "tsCurrency");
                waf("#" + tsCurrency).wafPromptBox("option","disabled",true);
                 waf("#" + tsCurrency).wafPromptBox("setValue",null);
                var trafficSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficSubsidy");
                waf("#" + trafficSubsidy).wafNumberField("option","disabled",true);
                waf("#" + trafficSubsidy).wafNumberField("setValue",0);
                var tsReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "tsReta");
                waf("#" + tsReta).wafNumberField("option","disabled",true);
               //公杂费补贴
               var pfCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "pfCurrency");
                waf("#" + pfCurrency).wafPromptBox("option","disabled",false);
                  waf("#" + pfCurrency).wafPromptBox("setValue",currencyType);
                var publicFees = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "publicFees");
                waf("#" + publicFees).wafNumberField("option","disabled",true);
                var pfReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "pfReta");
                waf("#" + pfReta).wafNumberField("option","disabled",true);
               // 生活补贴
                var lifeSubsidyCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidyCurrency");
                waf("#" + lifeSubsidyCurrency).wafPromptBox("option","disabled",true);
                 waf("#" + lifeSubsidyCurrency).wafPromptBox("setValue",null);
                var lifeSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidy");
                waf("#" + lifeSubsidy).wafNumberField("option","disabled",true);
                 waf("#" + lifeSubsidy).wafNumberField("setValue",0);
                var lifeSubsidyReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidyReta");
                waf("#" + lifeSubsidyReta).wafNumberField("option","disabled",true);
               }
              //交通费
                var trafficCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficCurrency");
                waf("#" + trafficCurrency).wafPromptBox("option","disabled",false);
               waf("#" + trafficCurrency).wafPromptBox("setValue",currencyType);
                var trafficRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficRate");
                waf("#" + trafficRate).wafNumberField("option","disabled",true);
             //会务费
                var meetingCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "meetingCurrency");
                waf("#" + meetingCurrency).wafPromptBox("option","disabled",false);
                waf("#" + meetingCurrency).wafPromptBox("setValue",currencyType);
                var mettingRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "mettingRate");
                waf("#" + mettingRate).wafNumberField("option","disabled",true);	
				//其它费用
                var otherCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "otherCurrency");
                waf("#" + otherCurrency).wafPromptBox("option","disabled",false);
                waf("#" + otherCurrency).wafPromptBox("setValue",currencyType);
                var otherRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "otherRate");
                waf("#" + otherRate).wafNumberField("option","disabled",true);		
          }else{   //国内
               //职务等级
                var duty = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "duty");
                waf("#" + duty).wafSelect("option","disabled",false);
                //季节
                var season = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "season");
                waf("#" + season).wafSelect("option","disabled",false);
                //职称
                var jobName = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "jobName");
                waf("#" + jobName).wafSelect("option","disabled",true);
                waf("#" + jobName).wafSelect("setValue",-1);
            
                 //交通费
                var trafficCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficCurrency");
                waf("#" + trafficCurrency).wafPromptBox("option","disabled",true);
                waf("#" + trafficCurrency).wafPromptBox("setValue",null);
                var trafficRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficRate");
                waf("#" + trafficRate).wafNumberField("option","disabled",true);	
                //住宿费
                var hotelCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelCurrency");
                waf("#" + hotelCurrency).wafPromptBox("option","disabled",true);
                waf("#" + hotelCurrency).wafPromptBox("setValue",null);
                var hotelExpense = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelExpense");
                waf("#" + hotelExpense).wafNumberField("option","disabled",false);
                var putUpDay = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "putUpDay");
                waf("#" + putUpDay).wafNumberField("option","disabled",false);
                var hotelRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "hotelRate");
                waf("#" + hotelRate).wafNumberField("option","disabled",true);	
				//会务费
                var meetingCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "meetingCurrency");
                waf("#" + meetingCurrency).wafPromptBox("option","disabled",true);
                waf("#" + meetingCurrency).wafPromptBox("setValue",null);
                var mettingRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "mettingRate");
                waf("#" + mettingRate).wafNumberField("option","disabled",true);	
				//其它费用
                var otherCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "otherCurrency");
                waf("#" + otherCurrency).wafPromptBox("option","disabled",true);
                waf("#" + otherCurrency).wafPromptBox("setValue",null);
                var otherRate = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "otherRate");
                waf("#" + otherRate).wafNumberField("option","disabled",true);					
			   //伙食补贴
                var fsCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "fsCurrency");
                waf("#" + fsCurrency).wafPromptBox("option","disabled",true);
                waf("#" + fsCurrency).wafPromptBox("setValue",null);
                var foodSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "foodSubsidy");
                waf("#" + foodSubsidy).wafNumberField("option","disabled",true);
                var fsReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "fsReta");
                waf("#" + fsReta).wafNumberField("option","disabled",true);
               	//交通补贴
               var tsCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "tsCurrency");
                waf("#" + tsCurrency).wafPromptBox("option","disabled",true);
                waf("#" + tsCurrency).wafPromptBox("setValue",null);
                var trafficSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "trafficSubsidy");
                waf("#" + trafficSubsidy).wafNumberField("option","disabled",true);
                var tsReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "tsReta");
                waf("#" + tsReta).wafNumberField("option","disabled",true);   
               //公杂费补贴
               var pfCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "pfCurrency");
                waf("#" + pfCurrency).wafPromptBox("option","disabled",true);
                waf("#" + pfCurrency).wafPromptBox("setValue",null);
                var publicFees = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "publicFees");
                waf("#" + publicFees).wafNumberField("option","disabled",true);
                waf("#" + publicFees).wafNumberField("setValue",0);
                var pfReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "pfReta");
                waf("#" + pfReta).wafNumberField("option","disabled",true);
               // 生活补贴
                var lifeSubsidyCurrency = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidyCurrency");
                waf("#" + lifeSubsidyCurrency).wafPromptBox("option","disabled",true);
                waf("#" + lifeSubsidyCurrency).wafPromptBox("setValue",null);
                var lifeSubsidy = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidy");
                waf("#" + lifeSubsidy).wafNumberField("option","disabled",true);
                 waf("#" + lifeSubsidy).wafNumberField("setValue",0);
                var lifeSubsidyReta = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "lifeSubsidyReta");
                waf("#" + lifeSubsidyReta).wafNumberField("option","disabled",true);
          }
        }
    	,
		costCenterChange:function(event,value){
           var entryInfoBlock = waf("#entries");
               var rowid = entryInfoBlock.wafInfoBlock("getRowIdByEvent", event);
               var project = entryInfoBlock.wafInfoBlock("getControlId", rowid, "project");
               waf("#" + project).wafPromptStandard('option','filteritem',"admin.id='"+value.current.id+"'  or  admin.id = null");
        
          // 清空当前行费用类型
	    	if(bizCollBillEdit.isFieldOnLoad || !value.current) return;
	        var prmtCompanyId = entryInfoBlock.wafInfoBlock("getControlId", rowid, "company");
	        var prmtOperationTypeId = entryInfoBlock.wafInfoBlock("getControlId", rowid, "operationType");
	        var company = waf("#" + prmtCompanyId).wafPromptBox("getValue");
			var operationType = waf("#" + prmtOperationTypeId).wafPromptBox("getValue");
			var billType = _self.getBillType();
			if(operationType != null){
				operationTypeId = operationType.id;
			}
			var operationTypeId = (operationType && operationType.id) || "";
	       // if(company) return;
	        var costCenterId = value.current.id;
	        waf.doPost({
	            action: "onchange",
	            data: {source:"costCenter", costCenterId: costCenterId, operationTypeId: operationTypeId, billType: billType},
	            success: function(result){
	            	_public.isNeedClearCostCenter = false;
	            	waf("#" + prmtCompanyId).wafPromptBox("setValue", result.company);
	            	_public.isNeedClearCostCenter = true;
	            	var expenseTypeId = entryInfoBlock.wafInfoBlock("getControlId", rowid, "expenseType");
	            	waf("#" + expenseTypeId).wafPromptExpenseType("option", "companyId", result.company && result.company.id);
	            	if(result.isNeedClearOperationType){
	            		waf(".entry_expenseType input[ctrlrole='promptBox']").wafPromptBox("setValue", null);
					}
	            }
	        });
	        // 更新预算信息
	       if(!bizCollBillBase.isShowBudgetBalance() || bizCollBillEdit.isFieldOnLoad || !_public.needChangeEvent) return;
        	bizCollBillBase.showBgData(prop, value, isHeadChange, rowid, ifStore);
        }
    
    	,
		nameChange:function(event,ui){
        }
    	,
		initEntryGrid:function(e){
          // 分录信息块事件绑定
    		waf("#entries").wafInfoBlock("option", "afterInsertRow", function(rowid,rowdata,rowelem) {
    			var isMultiCurrency = waf("#cbMultiCurrency").wafCheckbox("isChecked");
    			if (!isMultiCurrency) {
    				// 未勾选多币别,隐藏多币别属性
    				waf(".currencyProperty").hide();
    			}
    			var ifTaxChecked = waf("#enableTaxCheckbox").wafCheckbox("isChecked");
    			if (!ifTaxChecked) {
    				// 未显示增值税,隐藏不含税住宿费、税率（%）、税额、不含税金额
    				waf(".enableTaxCheck").hide();    				
    			}
    			if (isMultiCurrency && ifTaxChecked) {
    				waf(".amountWithoutTax").wafNumberField("option", "hidden", false);
    			} else {
    				waf(".amountWithoutTax").wafNumberField("option", "hidden", true);
    			}
    			
    			// 项目显示/隐藏控制 
    			waf(".project").toggle(bizCollBillBase.isShowProject());
    			//电子发票显示/隐藏控制 标签容器样式类
    			waf(".ticketNumber").toggle(bizCollBillBase.isTicketInvoice());  
    			var ifOtherDept = waf("#cbOtherDept").wafCheckbox("isChecked"),
    				ifOtherCompany = waf("#cbOtherDeptAndCompany").wafCheckbox("isChecked");
    			if (ifOtherCompany) {
    			} else if (ifOtherDept) {
    				waf(".otherCompany").hide();
    				waf(".otherDept").show();
    			} else {
    				waf(".otherCompany").hide();
    			}
    			if(!bizCollBillBase.isShowBudgetBalance()) {
    				waf(".bgDataCL").hide();
    	        }
    			// 启用报销标准,则显示相关报销标准属性
    			if (_public.needAccountStandard) {
    				waf(".evectionStandard").show();
    				// 出差地域增加必输入性校验
    				var entry_travelAreaDom = waf(".entry_travelArea input[type='text']");
    				entry_travelAreaDom.wafPromptStandard("option", "selectors", "id, name");
    				entry_travelAreaDom.wafValidator("option", "rules", "required:true");
    				entry_travelAreaDom.wafPromptStandard("option", "beforeTableInit", _private.areaF7Init)
    			} else {
    				waf(".evectionStandard").hide();
    			}
              waf(".layoutColumn25_to").hide();
              
               var entryInfoBlock = waf("#entries");
              var curRowId = entryInfoBlock.wafInfoBlock("getCurrentRowId");
              //职务等级
               var duty = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "duty");
               waf("#" + duty).wafSelect("addOption", [{value:"-1",alias:""}],0);
               var dutyValue=waf("#" + duty).wafSelect("getValue");
              if(dutyValue=="-1"){
             		 waf("#" + duty).wafSelect("setValue",3);
              }
               //职称
               var jobName = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "jobName");
               waf("#" + jobName).wafSelect("addOption", [{value:"-1",alias:""}],0);
               //季节
               var season = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "season");
               waf("#" + season).wafSelect("addOption", [{value:"-1",alias:""}],0);
              
                var destinationCity = entryInfoBlock.wafInfoBlock("getControlId", curRowId, "destinationCity");
                waf("#"+destinationCity).wafPromptStandard("option","defaultSearchItem","city");
				 _private.entryDestinationCityFiltration();
    		});
           var model = _self.getCurrentModel(),
        		sumProps = _private.entrySumProps;
            var sumReta = _private.entrySumReta;
        	var oriEntries = model.entries;
        	for (var j = 0; j < oriEntries.length; j++) {
        		var entry = oriEntries[j];
    				entry.amountOri = 0;
     		
        		for (var i = 0, il = sumProps.length; i < il; i++) {        			
        			entry.amountOri +=((entry[sumProps[i]]) || 0)*((entry[sumReta[i]]) || 0);
        		}
        		var exchangeRate = entry.exchangeRate;
				var convertMode = entry.convertMode;
				var amount =  bizCollBillBase.ifConvertMode(convertMode) ? entry.amountOri / exchangeRate : 
					entry.amountOri * exchangeRate;
        		entry.amount = amount; 
            }
          waf("#editGrid_entries").wafGrid("reloadGrid");
        }
    	,
		dutyOnClick:function(){
        }
    	,
		seasonOnClick:function(){
        }
	    ,
		dutyOnChange:function(event,ui){
            
        }
    	,
		moreVerifyData:function(e){
          _private.verifyData(e);
        }
    	,
		AllowanceDaysChange:function(event,value){
          TravelAccountBill_Edit_Open.entryAllowanceDaysChange(event,value);
          var entryInfoBlock = waf("#entries");
            var rowId = entryInfoBlock.wafInfoBlock("getCurrentRowId");
             //国内/国外
                var inlandForeign = entryInfoBlock.wafInfoBlock("getControlId", rowId, "inlandForeign");
                var inlandForeignValue=waf("#" + inlandForeign).wafSelect("getValue") || 0;
               //补贴天数
                //var subsidyDay = entryInfoBlock.wafInfoBlock("getControlId", rowId, "subsidyDay");
                //var subsidyDayValue=waf("#" + subsidyDay).wafNumberField("getValue") || 0;
            var startDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowId, "startDate");
    		var endDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowId, "endDate");
             var day=_private.calcSubDays(startDate,endDate);
          if(inlandForeignValue==2&&day>30){
              var hotelExpenseId = entryInfoBlock.wafInfoBlock("getControlId", rowId, "hotelExpense");
              waf("#" + hotelExpenseId).wafText("option","disabled",true);
          }
           var allowanceDaysId = entryInfoBlock.wafInfoBlock("getControlId", rowId, "allowanceDays");
          waf("#" + allowanceDaysId).wafNumberField("setValue",0);
        }
    	,
		jobNameOnChange:function(event,ui){
          _private.entryDestinationCityFiltration();
        }
    	,
		entryDestinationCityFiltration:function(){
            var entryInfoBlock = waf("#entries");
               var rowid = entryInfoBlock.wafInfoBlock("getCurrentRowId");
          
                //国内/国外
                var inlandForeign = entryInfoBlock.wafInfoBlock("getControlId", rowid, "inlandForeign");
                var inlandForeignValue=waf("#" + inlandForeign).wafSelect("getValue");
               //补贴天数
            var startDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "startDate");
    		var endDate = entryInfoBlock.wafInfoBlock("getFieldValue", rowid, "endDate");
             var day=_private.calcSubDays(startDate,endDate);
            //职称
                var jobName = entryInfoBlock.wafInfoBlock("getControlId", rowid, "jobName");
                var jobNameValue=waf("#" + jobName).wafSelect("getValue") || 0;
          
              var condition="inlandForeign="+inlandForeignValue;
          if(inlandForeignValue==2){
             if(day!=null){
               var timeIimit=0;
               if(day<=30){
                  timeIimit=1;
               }else if (day>30&&day<90){
                 timeIimit=2;
              }else{
                 timeIimit=3;
              }
                condition+=" and timeIimit="+timeIimit;
         	 }
          }
            
            if(jobNameValue!=-1){
                 condition+=" and dutyTitle="+jobNameValue;
              }
               var destinationCity = entryInfoBlock.wafInfoBlock("getControlId", rowid, "destinationCity");
               waf("#" + destinationCity).wafPromptStandard('option','filteritem', condition);
               
         // var city=waf("#" + destinationCity).wafPromptStandard('getValue');
         //      if(city==null){
          //         return;
          //     }
          	//   var option=_self.getOptionFromArguments(arguments);
            //       option.action="EvectionSubsiAction";
            //       option.data={"id":city.id,"day":day,"inlandForeignValue":inlandForeignValue,"jobNameValue":jobNameValue};
             //      option.async=false;
             //      option.success=function(data){
             //         if(data==null){
              //        waf("#" + destinationCity).wafPromptStandard('setValue', null);
              //        }
              //     }
              //     waf.doPost(option);
        }
    	,
		calcSubDays:function(startDate, endDate){
          // 计算两个日期的差值,返回天数,参数为date或者格式为"yy-mm-dd"的字符串
        	if (!startDate || !endDate) {
        		return 0;
        	}
        	if (!(startDate instanceof Date)) {
        		// startDate转换为Date类型
        		var values = startDate.split("-");
        		startDate = new Date(values[0], values[1] - 1, values[2]);
        	}
        	if (!(endDate instanceof Date)) {
        		// endDate转换为Date类型
        		var values = endDate.split("-");
        		endDate = new Date(values[0], values[1] - 1, values[2]);
        	}
    		var days = ((endDate - startDate) / (1000 * 60 * 60 * 24));
    		if (days >= 0) {
    			return days ;
    		} else {
    			// 非法时间差返回0天
    			return 0;
    		}
        }
    	,
		entryIsCrossSeason:function(){
          	  var entry = waf("#entries");
              var rowid = entry.wafInfoBlock("getCurrentRowId");
              var inlandForeign = entry.wafInfoBlock("getFieldValue", rowid, "inlandForeign");
              if(inlandForeign==2){
						return;
              }
              var startDate = entry.wafInfoBlock("getFieldValue", rowid, "startDate");
			  if(null==startDate){
              	return;
              }     
              var endDate = entry.wafInfoBlock("getFieldValue", rowid, "endDate");
			  if(null==endDate){
              	return;
              }   
              var putUpDay = entry.wafInfoBlock("getFieldValue", rowid, "putUpDay");
			  if(null==putUpDay){
              	return;
              } else if( putUpDay=="0"){
                  var checkInDate = entry.wafInfoBlock("getControlId", rowid, "checkInDate");
                  waf("#" + checkInDate).wafDatePicker("option","disabled",true);
                  waf("#" + checkInDate).wafDatePicker("setValue",null);
                  var checkOutDate = entry.wafInfoBlock("getControlId", rowid, "checkOutDate");
                  waf("#" + checkOutDate).wafDatePicker("option","disabled",true);
                  waf("#" + checkOutDate).wafDatePicker("setValue",null);
                	return;
              }
              var entryData=entry.wafInfoBlock("getData")[0];
              var option=_self.getOptionFromArguments(arguments);
              option.action="PutUpVerifyAction";
              option.data={"data":JSON.stringify(entryData)};
              option.async=false;
              option.success=function(data){
                if(data.result==false){
                  var checkInDate = entry.wafInfoBlock("getControlId", rowid, "checkInDate");
                  waf("#" + checkInDate).wafDatePicker("option","disabled",false);
                  var checkOutDate = entry.wafInfoBlock("getControlId", rowid, "checkOutDate");
                  waf("#" + checkOutDate).wafDatePicker("option","disabled",false);
                }else{
                  var checkInDate = entry.wafInfoBlock("getControlId", rowid, "checkInDate");
                  waf("#" + checkInDate).wafDatePicker("option","disabled",true);
                  waf("#" + checkInDate).wafDatePicker("setValue",null);
                  var checkOutDate = entry.wafInfoBlock("getControlId", rowid, "checkOutDate");
                  waf("#" + checkOutDate).wafDatePicker("option","disabled",true);
                  waf("#" + checkOutDate).wafDatePicker("setValue",null);
                }
              }
              waf.doPost(option);
        }
    	,
		startDateChange:function(changeValue,inst){
           _private.entryControlChange();
          _private.entryIsCrossSeason();
           _private.entryDestinationCityFiltration();
        }
	    ,
        endDateChange:function(changeValue,inst){
           _private.entryControlChange();
           _private.entryIsCrossSeason();
           _private.entryDestinationCityFiltration();
        }
    });//@endPrivate
    /**************************开发区域结束**********************************************/
    return _public;
});
